﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CRM.Entity;
using CRM.Common;

namespace CRM.Controller.Validation
{
    public class InputValidation
    {
        #region 对News_Detail中各个字段的验证
        /// <summary>
        /// 对News_Detail中各个字段的验证
        /// </summary>
        /// <param name="news_Detail"></param>
        /// <returns></returns>
        public static bool CheckNews_Detail(News_Detail news_Detail,bool isCheckPrimary = true)
        {
            //只过滤字符串类型，剔除特殊字符
              news_Detail.title = Utils.RemoveStript(news_Detail.title);
              news_Detail.content = Utils.RemoveStript(news_Detail.content);

            //然后判断字符长度
               if (news_Detail.news_id>long.MaxValue)
               return false;
                 if(news_Detail.title.Length > 100)
                return false;
                 if(news_Detail.content.Length > 2000)
                return false;
                if (news_Detail.create_time< DateTime.Parse("1753-1-1"))
                return false;
                if (news_Detail.last_modify_time< DateTime.Parse("1753-1-1"))
                return false;
            return true;
        }
        #endregion      
      
        #region 对News_Type中各个字段的验证
        /// <summary>
        /// 对News_Type中各个字段的验证
        /// </summary>
        /// <param name="news_Type"></param>
        /// <returns></returns>
        public static bool CheckNews_Type(News_Type news_Type,bool isCheckPrimary = true)
        {
            //只过滤字符串类型，剔除特殊字符
              news_Type.type_name = Utils.RemoveStript(news_Type.type_name);
              news_Type.type_image = Utils.RemoveStript(news_Type.type_image);

            //然后判断字符长度
               if (news_Type.type_id>long.MaxValue)
               return false;
                 if(news_Type.type_name.Length > 20)
                return false;
                 if(news_Type.type_image.Length > 100)
                return false;
                if (news_Type.create_time< DateTime.Parse("1753-1-1"))
                return false;
            return true;
        }
        #endregion      
      
        #region 对Sys_UserInfo中各个字段的验证
        /// <summary>
        /// 对Sys_UserInfo中各个字段的验证
        /// </summary>
        /// <param name="sys_UserInfo"></param>
        /// <returns></returns>
        public static bool CheckSys_UserInfo(Sys_UserInfo sys_UserInfo,bool isCheckPrimary = true)
        {
            //只过滤字符串类型，剔除特殊字符
              sys_UserInfo.user_name = Utils.RemoveStript(sys_UserInfo.user_name);
              sys_UserInfo.password = Utils.RemoveStript(sys_UserInfo.password);

            //然后判断字符长度
               if (sys_UserInfo.user_id>long.MaxValue)
               return false;
                 if(sys_UserInfo.user_name.Length > 50)
                return false;
                 if(sys_UserInfo.password.Length > 50)
                return false;
                if (sys_UserInfo.user_type>int.MaxValue)
                return false;
                if (sys_UserInfo.create_time< DateTime.Parse("1753-1-1"))
                return false;
                if (sys_UserInfo.last_login_time< DateTime.Parse("1753-1-1"))
                return false;
            return true;
        }
        #endregion      
      

    }
}
